package robotleMvc
{

	import _Pan3D.role.MeshDataManager;
	import _Pan3D.texture.TextureManager;

	import _me.Config;
	import _me.Scene_data;

	import com.net.LibData;
	import com.net.RESManager;
	import com.net.SWFLoader;

	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.display3D.Context3D;
	import flash.events.Event;

	import newPan3d.content.scene.PanSceneLevel;

	import robotleMvc.frameworks.AppContext;
	import robotleMvc.ui.scene3D.Scene3DView;
	import robotleMvc.ui.uiContainers.UiContainer;
	import newPan3d.ui.UiView;

	// --------------MSN:lation_pan@live.cn  QQ: 3423526------------- //
	[SWF(backgroundColor="#FFFFFF", frameRate="60", width="1024", height="600")]
	public class MvcIndex extends MovieClip
	{
		private var _res:RESManager;
		private var context:AppContext;
		private var uiContainer:UiContainer;
		private var stage3dSceneView:Scene3DView;
		private var _sceneView:PanSceneLevel;
		private var _uiView:UiView=new UiView;

		public function MvcIndex()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, addToStage)
		}
		private function addToStage(evt:Event):void
		{
			initData();
		}
		private function initData():void
		{
			_res=new RESManager;
			_res.add(new SWFLoader(new LibData("ui.swf"))); //加载UI适用于CAFE的框架
			_res.addEventListener(Event.COMPLETE, uiSwfLoadComPlete);
			_res.load();
		}
		private function uiSwfLoadComPlete(event:Event):void
		{
			stage.scaleMode=StageScaleMode.NO_SCALE
			stage.align=StageAlign.TOP_LEFT;
			stage.displayState == StageDisplayState.FULL_SCREEN
			context=new AppContext(this); //robotle框架管理
			uiContainer=new UiContainer;
			addChild(uiContainer);
			Scene_data.stage=this.stage;
			Scene_data.root=this;
			initScene3D();
		}
		private function initScene3D():void
		{
			addChild(_uiView);
			Scene_data.fileRoot="http://pan3dme.lt6.nns.cc/pan3D/yizhan/_File/nijia2/";
			Scene_data.fileRoot="../_File/nijia2/";
			Config.init(stage, _config_end);
		}
		private function _config_end():void
		{
			var context3D:Context3D=Scene_data.context3D;
			TextureManager.getInstance().init(context3D);
			MeshDataManager.getInstance().init(context3D);
			_sceneView=new PanSceneLevel;
			_sceneView.initData();
			Scene_data.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			Scene_data.stage.addEventListener(Event.RESIZE, stageResize)
			stage.scaleMode=StageScaleMode.NO_SCALE
			stage.align=StageAlign.TOP_LEFT;
			stageResize(new Event(Event.RESIZE))
		}

		protected function stageResize(event:Event):void
		{
			Scene_data.stageWidth=stage.stageWidth;
			Scene_data.stageHeight=stage.stageHeight;
			_sceneView.stageResize();
		}

		private function onEnterFrame(event:Event):void
		{
			_sceneView.upData();

		}
		public function get uiView():UiView
		{
			return _uiView;
		}
	}
}
